using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
namespace LabMS.Web.CommonPage
{
    public partial class CourseList2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DataBinds();
            }
        }

        protected void DataBinds()
        {
            Gv_DataBind();
        }
        protected void Gv_DataBind()
        {
            LabMS.BLL.Course Course = new LabMS.BLL.Course();
            List<LabMS.Model.Course> ls = new List<LabMS.Model.Course>();
            ls = Course.GetModelList(CombineStr());
            Gv_Course.DataSource = ls;
            Gv_Course.DataBind();

        }
        protected string CombineStr()
        {
            string strWhere = "";
            if (ddl_SearchType.SelectedValue == "0" && !string.IsNullOrEmpty(tb_KeyWord.Text.Trim()))
            {
                strWhere += " Course_Code like '" + tb_KeyWord.Text.Trim() + "'";
            }
            else if (ddl_SearchType.SelectedValue == "1" && !string.IsNullOrEmpty(tb_KeyWord.Text.Trim()))
            {
                strWhere += " Course_Name like '" + tb_KeyWord.Text.Trim() + "'";
            }
            return strWhere;
        }

        protected void btn_Search_Click(object sender, EventArgs e)
        {
            Gv_DataBind();
        }

        protected void Gv_Course_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
            Gv_Course.PageIndex = e.NewSelectedIndex;
            Gv_DataBind();
        }

        protected void Gv_Course_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6f5fa'");
                //e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
                e.Row.Attributes["style"] = "Cursor:pointer";
                e.Row.Attributes.Add("OnDblClick", "DbClickEvent('" + e.Row.Cells[0].Text + "','" + e.Row.Cells[1].Text + "','" + Gv_Course.DataKeys[e.Row.RowIndex].Value.ToString() + "')");

            }
        }
    }
}
